package cli

import (
	"blockchain.com/part_5/block"
	"blockchain.com/part_5/wallet"
	"log"
	"fmt"
)

// 实现发送币命令行
func (cli *CLI)Send(from,to string,amount int)  {
	if  !wallet.ValidateAddress(from){
		log.Panic("ERROR: Sender address is not valid.")
	}

	if !wallet.ValidateAddress(to) {
		log.Println("ERROR: Recipient address is not valid")
	}

	bc := block.NewBlockchain(from)
	defer bc.Db.Close()

	tx := block.NewUTXOTransaction(from,to,amount,bc)
	bc.MineBlock([]*block.Transaction{tx})

	fmt.Println("Success!")
}